package uk.ac.cam.cl.projectcharlie2010.camera;

import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MoreCameraTests {

	public static void main(String args[]) throws IOException {
		BufferedImage calibrationImage;
		URL calibrationImageURL;
		calibrationImageURL = new URL("http://192.168.1.90/jpg/image.jpg");
		
		String SETTINGS_DIR_LOCATION = System.getProperty("user.home") + "/.charlies";
		
		String location = SETTINGS_DIR_LOCATION; //  + "/calibrationImage.jpg";
		
		File calibrationImageLocation = new File(location);
		
		calibrationImageLocation.mkdir();
		
		location = SETTINGS_DIR_LOCATION + "/calibrationImage.jpg";
		
		calibrationImageLocation = new File(location);
		
		calibrationImage = ImageIO.read(calibrationImageURL);
		ImageIO.write(calibrationImage,"jpg",calibrationImageLocation);	
////		displayImage(calibrationImage);
//		BufferedImage maskImage = ImageIO.read(new File("resources/camera/mask.png"));
////		BufferedImage maskImage = ImageIO.read(new File("c://mask.png"));
////		BufferedImage maskImage = ImageIO.read(new File("c://mask.png"));
//		displayImage(maskImage);
	}


	private static void displayImage(BufferedImage image){
		JFrame frame = new JFrame(); 
		JLabel label = new JLabel(new ImageIcon(image)); 
		frame.getContentPane().add(label, BorderLayout.CENTER); 
		frame.pack(); frame.setVisible(true);
	}

}
